
//注册功能
function register() {
    let account = document.getElementById("account").value;
    let password = document.getElementById("password").value;
    let rePassword = document.getElementById("rePassword").value;
    let securityCode = document.getElementById("securityCode").value;
    let confirmButton = document.getElementById("confirmButton").value;
    let emailPattern = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    let passwordPattern = /^.*(?=.{6,15})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
    if (account === "" || password === "" || rePassword === "" || securityCode === "") {
        alert("填写信息不能为空");
        return ;
    } else {
        //验证两次密码是否一致
        if (password !== rePassword) {
            alert("两次密码输入不一致");
            return;
        } else {
            if (passwordPattern.test(password)) {
                if (emailPattern.test(account)) {
                    document.getElementById("form").submit();//表单提交数据
                } else {
                    alert("邮箱格式错误");
                    return;
                }
            } else {
                //密码强度以及格式
                alert("密码长度为6~16，且必须包含至少1个大写字母、1个小写字母、1个数字、1个特殊字符");
                return;
            }
        }
    }
}
//发送验证码
function getSecurityMode(){
    let account=document.getElementById("account").value;
    let password=document.getElementById("password").value;
    let rePassword=document.getElementById("rePassword").value;
    let confirmButton=document.getElementById("confirmButton");
    let filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(account===""||password===""||rePassword===""){
        alert("填写信息不能为空");
    }else{
        if(password===rePassword&&filter.test(account)) {
            let xmlHttpRequest = createAjaxFunction();//创建ajax对象
            confirmButton.disableb= true;//按钮失效
            confirmButton.color="#EAEAEA";//改变颜色，增加视觉效果
            let count = 60;
            countTimes();
            function countTimes() {
                confirmButton.innerText = "" + count + "s";
                count--;
                if (count > 0) {
                    setTimeout(countTimes, 1000);
                } else if (count === 0) {
                    confirmButton.innerText = "重新发送";
                    confirmButton.disabled = false; //重新激活按钮
                    confirmButton.color = "#00FFFF";
                }
            }
            xmlHttpRequest.open("GET", "SendEmailServlet?qqEmail=" + account, true);
            xmlHttpRequest.send();
        }else{
            alert("邮箱格式错误或密码输入不一致");
        }
    }
}
//创建xmlHttpRequest对象
function createAjaxFunction() {
    let xmlHttp;
    //根据不同的浏览器构建ajax对象
    try {
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}